layui.use(["form", "ax", "admin"], function () {
    var $ = layui.$;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    form.verify({
        cardNum: [/^[0-9a-zA-Z]{1,32}$/, "请输入不超过32个数字及字母"],
        tacVer:[/^[0-9]{0,32}$/, "请输入不超过32个数字字符"],
        imeiVer: [/^[0-9]{0,32}$/, "请输入不超过32个数字字符"]
    });

    form.on("select(bindFor)", function (data) {
        var bindForVal = data.value;
        //话单侧
        if (bindForVal == "0") {
            //显现绑定方式
            $("#bindingStyleDiv").show();

            $("#cdrShowIMEI").removeClass("layui-hide");
            $("#webShowIMEI").addClass("layui-hide");
            $("#cdrShowAttention").removeClass("layui-hide");
            $("#webShowAttention").addClass("layui-hide");
        //网络侧
        } else if (bindForVal == "1") {
            //隐藏绑定方式
            $("#bindingStyleDiv").hide();

            $("#cdrShowIMEI").addClass("layui-hide");
            $("#webShowIMEI").removeClass("layui-hide");
            $("#cdrShowAttention").addClass("layui-hide");
            $("#webShowAttention").removeClass("layui-hide");
        }
    });

    form.on('submit(btnSubmit)', function (data) {
        var bindForVal = $("#bindFor").val();
        var url = "";
        //绑定类型
        var operTypeVal = $("#operType").val();
        //绑定方式
        var bindingStyleVal = $("#bindingStyle").val();
        var tacVal = $("#tac").val();
        var imeiVal = $("#imei").val();

        //话单侧
        if (bindForVal == "0") {
            if (operTypeVal == "1") {
                if (bindingStyleVal == "") {
                    Feng.error("绑定类型为1时，绑定方式必需选0或1!");
                    return false;
                }
            } else if (operTypeVal == "3") {
                if (bindingStyleVal != "1") {
                    Feng.error("绑定类型为3时，绑定方式必需选1!");
                    return false;
                }
            }
            if (bindingStyleVal == "1" && tacVal == "") {
                Feng.error("绑定方式为1时，IMEI值不能为空！");
                return false;
            }
            url = Feng.ctxPath + "/security/cardBindForCdr";
        //网络侧
        } else {
            if (imeiVal == "") {
                Feng.error("请输入IMEI值！");
                return false;
            }
            url = Feng.ctxPath + "/security/cardBindForWeb";
        }

        var ajax = new $ax(url, function (data) {
            layer.open({
                content: "操作成功！",
                skin: 'layui-layer-molv',
                yes: function (index, layero) {
                    admin.closeThisDialog();
                }
            });
        }, function (data) {
            layer.open({
                content: "操作失败！" + data.responseJSON.message,
                skin: 'layui-layer-molv',
                yes: function (index, layero) {
                    layer.close(index);
                }
            });
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });
});
